home *** CD-ROM | disk | FTP | other *** search
- Error Reporting
- Previous: <Lexical=>Lexical> * Next: <Action Features=>ActionFeat> * Up: <Interface=>Interface>
-
- #Wrap on
- {fH3}The Error Reporting Function {fCode}yyerror{f}{f}
-
- The Bison parser detects a {fUnderline}parse error{f} or {fUnderline}syntax error{f}
- whenever it reads a token which cannot satisfy any syntax rule. A
- action in the grammar can also explicitly proclaim an error, using the
- macro {fCode}YYERROR{f} (\*Note <Action Features=>ActionFeat>: Special Features for Use in Actions).
-
- The Bison parser expects to report the error by calling an error
- reporting function named {fCode}yyerror{f}, which you must supply. It is
- called by {fCode}yyparse{f} whenever a syntax error is found, and it
- receives one argument. For a parse error, the string is normally
- {fCode}"parse error"{f}.
-
- If you define the macro {fCode}YYERROR\_VERBOSE{f} in the Bison declarations
- section (\*Note <Bison Declarations=>BisonDecla>: The Bison Declarations Section), then Bison provides a more verbose
- and specific error message string instead of just plain {fCode}"parse
- error"{f}. It doesn't matter what definition you use for
- {fCode}YYERROR\_VERBOSE{f}, just whether you define it.
-
- The parser can detect one other kind of error: stack overflow. This
- happens when the input contains constructions that are very deeply
- nested. It isn't likely you will encounter this, since the Bison
- parser extends its stack automatically up to a very large limit. But
- if overflow happens, {fCode}yyparse{f} calls {fCode}yyerror{f} in the usual
- fashion, except that the argument string is {fCode}"parser stack
- overflow"{f}.
-
- The following definition suffices in simple programs:
-
- #Wrap off
- #fCode
- yyerror (s)
- char \*s;
- \{
- fprintf (stderr, "%s\\n", s);
- \}
- #f
- #Wrap on
-
- After {fCode}yyerror{f} returns to {fCode}yyparse{f}, the latter will attempt
- error recovery if you have written suitable error recovery grammar rules
- (\*Note <Error Recovery=>ErrorRecov>). If recovery is impossible, {fCode}yyparse{f} will
- immediately return 1.
-
- The variable {fCode}yynerrs{f} contains the number of syntax errors
- encountered so far. Normally this variable is global; but if you
- request a pure parser (\*Note <Pure Decl=>PureDecl>: A Pure (Reentrant) Parser) then it is a local variable
- which only the actions can access.
-
-